using Microsoft.AspNetCore.Mvc;
using ZR.Model.Dto;
using ZR.Model.System;
using ZR.Service.System.ISystemService;
using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters;

//创建时间：2023-10-30
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 生成配置
    /// </summary>
    [Verify]
    [Route("system/GenConfig")]
    public class GenConfigController : BaseController
    {
        /// <summary>
        /// 生成配置接口
        /// </summary>
        private readonly IGenConfigService _GenConfigService;

        public GenConfigController(IGenConfigService GenConfigService)
        {
            _GenConfigService = GenConfigService;
        }

        /// <summary>
        /// 查询生成配置列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "tool:genconfig:list")]
        public IActionResult QueryGenConfig([FromQuery] GenConfigQueryDto parm)
        {
            var response = _GenConfigService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询生成配置详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "tool:genconfig:query")]
        public IActionResult GetGenConfig(int Id)
        {
            var response = _GenConfigService.GetInfo(Id);
            
            var info = response.Adapt<GenConfig>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加生成配置
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "tool:genconfig:add")]
        [Log(Title = "生成配置", BusinessType = BusinessType.INSERT)]
        public IActionResult AddGenConfig([FromBody] GenConfigDto parm)
        {
            var modal = parm.Adapt<GenConfig>().ToCreate(HttpContext);

            var response = _GenConfigService.AddGenConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新生成配置
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "tool:genconfig:edit")]
        [Log(Title = "生成配置", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateGenConfig([FromBody] GenConfigDto parm)
        {
            var modal = parm.Adapt<GenConfig>().ToUpdate(HttpContext);
            var response = _GenConfigService.UpdateGenConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除生成配置
        /// </summary>
        /// <returns></returns>
        [HttpDelete("{ids}")]
        [ActionPermissionFilter(Permission = "tool:genconfig:delete")]
        [Log(Title = "生成配置", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteGenConfig(string ids)
        {
            int[] idsArr = Tools.SpitIntArrary(ids);
            if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }

            var response = _GenConfigService.Delete(idsArr);

            return ToResponse(response);
        }




    }
}